﻿//qlabelex.c
#include "qlabelex.h"
#include <QPixmap>
#include <QRgb>
#include <qDebug>

QLabelEx::QLabelEx(QWidget *parent) :
    QLabel(parent)
{

}
QLabelEx::~QLabelEx()
{

}
void QLabelEx::mousePressEvent(QMouseEvent *e)
{   
    QPoint mouse_local_pos = e->pos();
    QPixmap pixmap = this->grab(QRect(mouse_local_pos, QSize(1,1)));//截图1个像素
    QRgb rgb = pixmap.toImage().pixel(0,0);
    //qDebug()<<"鼠标位置:"<<mouse_local_pos;
    //qDebug()<<"鼠标颜色:"<<QColor(rgb);
    emit mouse_pressed( mouse_local_pos, QColor(rgb) );//发信号
}
